"""author: zsw
   data: 2021/12/12
   project: aaaaaaa我爱学习
"""
#使用类实现迭代器，实现斐波拉契数列
# class F():
#     def __init__(self):
#         self.a,self.b=0,1
#     def __iter__(self):
#         return self
#     def __next__(self):
#         self.a, self.b = self.b, self.a + self.b
#         if self.a>100:
#             raise StopIteration
#         else:
#             return self.a
# for i in F():
#     print(i)




#使用面向对象做一个ATM（存取款功能）

def login():
    dict1 = {"zsw": "123456"}
    user_money=10000
    i = 0
    while i < 3:
        username1 = input("请输入您的用户名：")
        userpasswd1 = input("请输入您的密码：")
        if (username1, userpasswd1) in dict1.items():
            print("登录成功")
            i = 4
        else:
            print(f"登录失败，您还有{3 - i - 1}次机会")
            i = i + 1
    print(f"您的余额为:{user_money}")

def welcome():
        print("菜单：".center(50, "*"))
        print("1.注册              2.登录".center(50, ' '))
        print("3.取款              4.存款".center(50, ' '))
        print("5.查看余额           6.退出".center(50, ' '))
        print("*".center(53, "*"))

def register():
        dict1 = {"zsw": "123456"}
        # print("请注册".center(50,"*"))
        while 1:
            username2=input("请输入您要注册的用户名：".rjust(25,' '))
            userpasswd2=input("请输入注册的密码：".rjust(25,' '))
            if username2=='q' or userpasswd2=='q':
                break
            elif username2 in dict1.keys():
                print("该用户已存在，请重新注册！".center(50,' '))
            else:
                dict1.update({username2:userpasswd2})
                print(f"用户{username2}注册成功！".center(50,' '))
                print(f"当前用户有：{format(dict1.keys())}".center(50,' '))

class ATM():
    area="changsha"
    def __init__(self,money):
        self.money=money
    def draw_money(self,get_money):
        if get_money<=self.money:
            self.money=self.money-get_money

        else:
            print("您的余额不足")
    def add_money(self,add_money):
            self.money=self.money+add_money


class User(ATM):
    def __init__(self,username,userpasswd,money):
        self.username=username
        self.userpasswd=userpasswd
        self.money=money
# a=ATM()
a = ATM(50000)
user=User("zsw","123456",5000)

while 1:
    welcome()
    num1 = input("请输入你的选择：".rjust(25, " "))
    num1=int(num1)
    if num1==1:
        print("请注册".center(50, "*"))
        register()
    elif num1==2:
        print("请登录：".center(50, "*"))
        login()
    elif num1==3:
        x=int(input("取多少钱?"))
        a.draw_money(x)
        user.draw_money(x)
        print(f"取了{x},剩下{user.money}")
    elif num1==4:
        x=int(input("存多少钱?"))
        a.add_money(x)
        user.add_money(x)
        print(f"存了{x},剩下{user.money}")
    elif num1==5:
        print("余额为：",user.money)
    elif num1==6:
        break